package reflect;

import java.lang.reflect.Constructor;

/**
 * 分别使用无参和有参构造器实例化Student
 */
public class Test1 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("reflect.Student");

        //无参构造器
        Object o1 = cls.newInstance();
        System.out.println(o1);

        //使用有参构造器
        //Student(String name, int age, char gender)
        Constructor c = cls.getConstructor(String.class,int.class,char.class);
        Object o2 = c.newInstance("张三",22,'男');
        System.out.println(o2);
    }
}
